package com.hq.shop08goods.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hq.shop08goods.entity.GoodsType;
import com.hq.shop08goods.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    @GetMapping("getGoodsList")
    public List<GoodsType> getGoodsList() {
        return goodsTypeService.list();
    }

    @PostMapping("addGoods")
    public boolean addGoods(@RequestBody GoodsType goodsType) {
        return goodsTypeService.save(goodsType);
    }

    @PostMapping("updateGoodsType")
    public boolean updateGoodsType(@RequestBody GoodsType goodsType) {
        return goodsTypeService.updateById(goodsType);
    }

    @GetMapping("deleteGoodsType/{id}")
    public boolean deleteGoodsType(@PathVariable Integer id) {
        return goodsTypeService.removeById(id);
    }

    @GetMapping("/getGoodsTypeListByPid/{id}")
    @ResponseBody
    public List<GoodsType> getGoodsTypeListByPid(@PathVariable Integer id) {
            QueryWrapper<GoodsType> wrapper = new QueryWrapper<>();
        wrapper.eq("goods_type_pid", id);
        return goodsTypeService.list(wrapper);
    }
}
